# coding: utf-8
import sys, os
BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_PATH)
from bs4 import BeautifulSoup
import requests
import json
from ip_common import log




def read_json(file_name):
    with open(BASE_PATH+'\\douban_data\\'+file_name, 'r', encoding="utf-8") as f:
        data = json.load(f)
    return data

def save_json(data,file_name):
    data = {"data":data}
    with open(BASE_PATH + '\\douban_data\\'+file_name, 'w',encoding="utf-8") as f:
        json.dump(data, f, indent=4,ensure_ascii=False)#ensure_ascii=False保证中文支持

def insert_data(data,file_name):
    source = read_json(file_name)
    source["data"].append(data)
    with open(BASE_PATH + '\\douban_data\\'+file_name, 'w',encoding="utf-8") as f:
        json.dump(source, f, indent=4,ensure_ascii=False)#ensure_ascii=False保证中文支持

